package com.ruijixiang.leetcode.everyday.leetcode2024.leetcode202409;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class leetcode20240909 {
    public ListNode mergeNodes(ListNode head){
        List<Integer> list=new ArrayList<>();
        int sum=0;
        while(head!=null){
            if(head.val==0){
                if(sum!=0) list.add(sum);
                sum=0;
            }else{
                sum+=head.val;
            }
            head=head.next;
        }
        ListNode res=new ListNode(0);
        ListNode resCpy=res;
        for(int num : list){
            ListNode tmp=new ListNode(num);
            resCpy.next=tmp;
            resCpy=resCpy.next;
        }
        return res.next;
    }
}
